package org.yelongframework.spring.cloud.zuul;

import javax.servlet.http.HttpServletRequest;

/**
 * Zuul路由服务工具类。可以获取通过路由转发的相对路径
 * 
 * @since 1.0.0
 */
public final class ZuulRouteServiceUtils {

	/** zuul路由转发时携带的请求头：路由的主机地址 localhost:10000 */
	public static final String x_forwarded_host = "x-forwarded-host";

	/** zuul路由转发时携带的请求头：路由转发请求的源协议 http */
	public static final String x_forwarded_proto = "x-forwarded-proto";

	/** zuul路由转发时携带的请求头：路由转发的前缀 /v1.0/project01 */
	public static final String x_forwarded_prefix = "x-forwarded-prefix";

	/** zuul路由转发时携带的请求头：路由的端口 10000 */
	public static final String x_forwarded_port = "x-forwarded-port";

	/** zuul路由转发时携带的请求头：请求路由的请求IP，及客户的IP地址。如果该请求还被nginx代理，则可能时nginx的地址 */
	public static final String x_forwarded_for = "x-forwarded-for";

	private ZuulRouteServiceUtils() {
	}

	/**
	 * @param request 请求
	 * @return 如果请求头中不存在则返回 <code>null</code>
	 * @see #x_forwarded_host
	 */
	public static String getForwardedHost(HttpServletRequest request) {
		return request.getHeader(x_forwarded_host);
	}

	/**
	 * @param request 请求
	 * @return 如果请求头中不存在则返回 <code>null</code>
	 * @see #x_forwarded_proto
	 */
	public static String getForwardedProto(HttpServletRequest request) {
		return request.getHeader(x_forwarded_proto);
	}

	/**
	 * @param request 请求
	 * @return 如果请求头中不存在则返回 <code>null</code>
	 * @see #x_forwarded_prefix
	 */
	public static String getForwardedPrefix(HttpServletRequest request) {
		return request.getHeader(x_forwarded_prefix);
	}

	/**
	 * @param request 请求
	 * @return 如果请求头中不存在则返回 <code>null</code>
	 * @see #x_forwarded_port
	 */
	public static String getForwardedPort(HttpServletRequest request) {
		return request.getHeader(x_forwarded_port);
	}

	/**
	 * @param request 请求
	 * @return 如果请求头中不存在则返回 <code>null</code>
	 * @see #x_forwarded_for
	 */
	public static String getForwardedFor(HttpServletRequest request) {
		return request.getHeader(x_forwarded_for);
	}

}
